package com.yzc.controller;

import com.yzc.pojo.UserBean;
import com.yzc.service.impl.UserBeanServiceImpl;
import com.yzc.util.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/userapi")
public class UserController {

    @Autowired
    private UserBeanServiceImpl userService;
    private static final Marker LOG_MARKER = MarkerFactory.getMarker("LOG");

    /**
     * 获取用户数据
     *
     * @return
     */
    @PostMapping("/loadAll")
    public List<UserBean> loadAll() {
        log.info(LOG_MARKER,"加载用户数据");
        return userService.loadaAll();
    }

    /**
     * 修改用户数据
     *
     * @return
     */
    @RequestMapping("/updateInfo")
    public Map updateInfo(@RequestBody UserBean userBean) {
        log.info(LOG_MARKER,"修改用户数据");
        return userService.updateInfo(userBean);
    }

    @RequestMapping("/updateXinxi")
    public Map updateXinxi(@RequestBody UserBean userBean) {
        log.info(LOG_MARKER,"修改用户信息");
        return userService.updateXinxi(userBean);
    }

    @RequestMapping("/updatePass")
    public Map updatePass(@RequestBody UserBean userBean) {
        log.info(LOG_MARKER,"修改用户密码");
        return userService.updatePass(userBean);
    }

    /**
     * 更新用户数据
     *
     * @return
     */
    @RequestMapping("/save")
    public Map save(@RequestBody UserBean userBean) {
        log.info(LOG_MARKER,"保存用户数据");
        return userService.saveInfos(userBean);
    }

    /**
     * 删除用户数据
     *
     * @return
     */
    @RequestMapping("/delete")
    public Map deleteInfo(@RequestBody UserBean userBean) {
        log.info(LOG_MARKER,"删除用户数据");
        return userService.deleteInfo(userBean);
    }

    /**
     * 查询用户数据
     *
     * @return
     */
    @RequestMapping("/selectInfos")
    public ResultData<List> selectInfos(@RequestParam("name") String name) {
        log.info(LOG_MARKER,"查询用户数据");
        return ResultData.success(userService.selectInfos(name));
    }

    /**
     * 根据id查询
     *
     * @return
     */
    @RequestMapping("/getInfoById")
    public UserBean getInfoById(@RequestParam("id") int id) {
        log.info(LOG_MARKER,"根据id查询用户数据");
        return userService.getInfoById(id);
    }




}
